<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('设备启停记录列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
	<style type="text/css">
		.table {table-layout:fixed;}
	</style>
</head>
<body class="gray-bg">
	<div class="ui-layout-west">
		<div class="box box-main">
			<div class="box-header">
				<div class="box-title">
					<i class="fa icon-grid"></i> 测点分组
				</div>
				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
					<button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
				</div>
			</div>
			<div class="ui-layout-content">
				<div id="tree" class="ztree"></div>
			</div>
		</div>
	</div>
	
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form" th:object="${data}">
		        <input type="hidden" id="groupid" name="groupid" th:field="*{groupid}">
		        <input type="hidden" name="tagid" th:field="*{tagid}" id="treeId"/>
						<div class="select-list">
							<ul>
								<li class="select-time">
                  <p>时间：</p>
                  <input type="text" class="time-input" id="startDate" placeholder="开始时间" name="startDate" th:field="*{startDate}"/>
                  <span>-</span>
                  <input type="text" class="time-input" id="endDate" placeholder="结束时间" name="endDate" th:field="*{endDate}"/>
                </li>
								<li>
									测点：<input type="text" name="tagname" onclick="selectTagTree()" id="treeName" th:field="*{tagname}" readonly="readonly"/>
								</li>
								 
								<li>
									<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								    <a class="btn btn-warning btn-rounded btn-sm" onclick="resets()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
								</li>
							</ul>
						</div>
					</form>
				</div>
				
        <div class="btn-group-sm" id="toolbar" role="group">
        	<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="startstop:record:export">
            <i class="fa fa-download"></i> 导出
         	</a>
        </div>
        
        <div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var queryFlag = [[${@permission.hasPermi('startstop:count:list')}]];
    var datatypeDatas = [[${@dict.getType('oos_overrun_datatype')}]];
    var caltypeDatas = [[${@dict.getType('sys_tag_caltype')}]];
    var limittypeDatas = [[${@dict.getType('sys_tag_limittype')}]];
    var prefix = ctx + "startstop/record";
		
		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 769) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 185 });
		    queryRecordList();
		    queryGroupTree();		    
		});

		// 重置事件
		function resets() {
			$("#user-form")[0].reset();
			$("#groupid").val("");
			$("#treeId").val("");
			$("#treeName").val("");
			$("#" + table.options.id).bootstrapTable('refresh');
		}
		
		function queryRecordList() {
		    var options = {
		    	url: prefix + "/list",
          exportUrl: prefix + "/export",
          modalName: "设备启停记录",
          columns: [{
              checkbox: true
          },
          {
              field : 'id', 
              title : '主键',
              visible: false
          },
          {
              field : 'groupid', 
              title : '测点分组id',
              visible: false
          },
          {
              field : 'groupname', 
              title : '测点分组名称',
              width : 150
          },
          {
              field : 'tagid', 
              title : '测点id',
              visible: false
          },
          {
              field : 'tagname1', 
              title : '测点名称',
              width : 200
          },
          {
              field : 'tagname', 
              title : 'PI测点名称',
              width : 200
          },
          {
              field : 'starttime', 
              title : '开始时间',
              width : 150,
              align: 'center'
          },
          {
              field : 'endtime', 
              title : '结束时间',
              width : 150,
              align: 'center'
          },
          {
              field : 'times', 
              title : '时长(分)',
              width : 120,
              align: 'center'
          },
         
          {
              field : 'calctype', 
              title : '计算类型',
              width : 120,
              align: 'center',
              formatter: function(value, row, index) {
                  return $.table.selectDictLabel(caltypeDatas, value);
               }
          },
          {
              field : 'limittype', 
              title : '限值类型',
              width : 120,
              align: 'center',
              formatter: function(value, row, index) {
                  return $.table.selectDictLabel(limittypeDatas, value);
               }
          },
          {
              field : 'datatype', 
              title : '数据类型',
              width : 120,
              align: 'center',
              formatter: function(value, row, index) {
                 return $.table.selectDictLabel(datatypeDatas, value);
              }
          }]
		    };
		    $.table.init(options);
		}

		// 测点图表操作
		function viewChart(id) {
			var url = prefix + '/echart/' + id;
			$.modal.open("设备启停线形图", url);
		}
		
		// 选择测点树
		function selectTagTree() {
			var tagid = $.common.isEmpty($("#treeId").val()) ? "0" : $("#treeId").val();
      var url = ctx + "tag/config/selectTagTree/" + tagid;
	    var options = {
				title: '选择测点',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		// 选择测点确定按钮
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
    			var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			$("#groupid").val(body.find('#treePid').val());
    			layer.close(index);
			}
		}

		function queryGroupTree()
		{
			var url = ctx + "tag/group/treeData";
			var options = {
        url: url,
        expandLevel: 2,
        onClick : zOnClick
		  };
			$.tree.init(options);
			
			function zOnClick(event, treeId, treeNode) {
				$("#groupid").val(treeNode.id);
				$("#treeId").val("");
				$("#treeName").val("");
				$.table.search();
			}
		}
		
		$('#btnExpand').click(function() {
			$._tree.expandAll(true);
		    $(this).hide();
		    $('#btnCollapse').show();
		});
		
		$('#btnCollapse').click(function() {
			$._tree.expandAll(false);
		    $(this).hide();
		    $('#btnExpand').show();
		});
		
		$('#btnRefresh').click(function() {
			queryGroupTree();
		});
	</script>
</body>
</html>